package com.jn.glide.presenter;

import android.content.Context;

import com.jn.glide.contract.AvatarContract;
import com.jn.glide.contract.MainContract;
import com.jn.glide.entity.AvatarEntity;
import com.jn.glide.service.AvatarService;
import com.jn.glide.service.MainService;
import com.jn.glide.utils.LogUtils;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class AvatarPresenter implements AvatarContract.IAvatarPresenter {
    private AvatarContract.IAvatarView mMainView;
    private Context mContext;

    public AvatarPresenter(AvatarContract.IAvatarView mMainView, Context mContext) {
        this.mMainView = mMainView;
        this.mContext = mContext;
    }

    @Override
    public void getData() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://api.oioweb.cn/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        AvatarService avatarService = retrofit.create(AvatarService.class);
        avatarService.getData().enqueue(new Callback<AvatarEntity>() {
            @Override
            public void onResponse(Call<AvatarEntity> call, Response<AvatarEntity> response) {
                LogUtils.d("asdf", "onResponse" + response.body());
                mMainView.showData(response.body());
            }

            @Override
            public void onFailure(Call<AvatarEntity> call, Throwable throwable) {
                LogUtils.d("asdf", "onResponse");
            }
        });
    }
}
